<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,height=device-height,initial-scale=1.0,user-scalable=0">
    <title>APICloud</title>
    <link rel="stylesheet" type="text/css" href="../css/base.css" />
    <link rel="stylesheet" type="text/css" href="../css/common.css" />
    <script type="text/javascript">

		var scanDeviceModule = null;
		apiready = function(){
	    	scanDeviceModule = api.require('scanDeviceModule');
	    }
		function scanDevice(){
			alert("开始查询设备");
			scanDeviceModule.scan(function(ret, err) {
    			document.getElementById("device_div").innerHTML = JSON.stringify(ret);
			});
		}
		function stopDevice(){
			alert("停止查询设备");
			scanDeviceModule.stop(function(ret, err) {
    			alert("设备停止");
			});
		}
		function connectedDevice(){
			alert("连接设备");
			var param = {device_name:"测试设备",device_address:"5C:31:3E:2A:BB:D8"};
			scanDeviceModule.connectedDevice(param,function(ret, err) {
				//连接返回状态 0:成功  ， 1:失败
    			alert(JSON.stringify(ret));
			});
		}
		function disConnectedDevice(){
			alert("关闭连接设备");
			var param = {device_name:"测试设备",device_address:"5C:31:3E:2A:BB:D8"};
			scanDeviceModule.disConnectedDevice(param,function(ret, err) {
				//连接返回状态 0:关闭连接 
    			alert(JSON.stringify(ret));
			});
		}
		function readDevice(){
			alert("读取设备信息");
			var param = {device_name:"测试设备",device_address:"5C:31:3E:2A:BB:D8",service_uuid:"0000FFF0-0000-1000-8000-00805F9B34FB",characteristic_uuid:"0000fff1-0000-1000-8000-00805f9b34fb"};
			scanDeviceModule.readDevice(param,function(ret, err) {
    			alert(JSON.stringify(ret));
			});
		}
		function startNotifyDevice(){
			alert("更新设备信息");
			var param = {device_name:"测试设备",device_address:"5C:31:3E:2A:BB:D8",service_uuid:"0000FFF0-0000-1000-8000-00805F9B34FB",characteristic_uuid:"0000fff1-0000-1000-8000-00805f9b34fb"};
			scanDeviceModule.startNotifyDevice(param,function(ret, err) {
    			alert(JSON.stringify(ret));
			});
		}
		function stopNotifyDevice(){
			alert("停止更新设备信息");
			var param = {device_name:"测试设备",device_address:"5C:31:3E:2A:BB:D8",service_uuid:"0000FFF0-0000-1000-8000-00805F9B34FB",characteristic_uuid:"0000fff1-0000-1000-8000-00805f9b34fb"};
			scanDeviceModule.stopNotifyDevice(param,function(ret, err) {
    			alert(JSON.stringify(ret));
			});
		}
		function writeDevice(){
			alert("写入设备信息");
			var param = {device_name:"测试设备",device_address:"5C:31:3E:2A:BB:D8",service_uuid:"0000FFF0-0000-1000-8000-00805F9B34FB",characteristic_uuid:"0000fff1-0000-1000-8000-00805f9b34fb",writeContent:"ABCDEF"};
			scanDeviceModule.writeDevice(param,function(ret, err) {
    			alert(JSON.stringify(ret));
			});
		}
    
	</script>
</head>
<body>
    <div id="wrap">
        <div id="main"> 
            <div  >
            <!--
            	<input type="button" onclick="showAlert()" value="弹出Alert" /><br><br>
            	<input type="button" onclick="startActivity()" value="启动Activity" /><br><br>
            	<input type="button" onclick="startActivityForResult()" value="启动Activity并获取该Activity的返回值" /><br><br>
            	<div style="font-size:0.8em;">acticity返回值:</div>
            	<div id="activity_result" style="width:100%;word-wrap: break-word;word-break: normal;"></div><br><br>
            	<div style="font-size:0.8em;">输入震动时间,单位：毫秒</div>
            	<input type="text" id="vibrate" value="20000" /><br><br>
            	<input type="button" onclick="vibrate()" value="开始震动" /><br>
            	<input type="button" onclick="stopVibrate()" value="停止震动" /><br><br>
            	<input type="button" onclick="addView()" value="添加自定义View到屏幕" /><br><br>
            	<input type="button" onclick="removeView()" value="从屏幕移除自定义View" /><br><br>
            	<input type="button" onclick="getProp()" value="获取属性" /><br><br>
            -->
            	<input type="button" onclick="scanDevice()" value="搜索设备" /><br><br>
            	<div id="device_div" style="width:100%;word-wrap: break-word;word-break: normal;"></div><br>
            	<input type="button" onclick="connectedDevice()" value="连接蓝牙设备" /><br><br>
            	<input type="button" onclick="disConnectedDevice()" value="关闭连接蓝牙设备" /><br><br>
            	<input type="button" onclick="readDevice()" value="读取设备设备信息" /><br><br>
            	<input type="button" onclick="startNotifyDevice()" value="更新设备信息" /><br><br>
            	<input type="button" onclick="stopNotifyDevice()" value="停止更新设备信息" /><br><br>
            	<input type="button" onclick="writeDevice()" value="写入设备信息" /><br><br>
            	<input type="button" onclick="stopDevice()" value="停止搜索设备" /><br><br>
            </div>

        </div>   
    </div>
</body>
</html>